//储存Cookie
export function setCookie(cname: string, cvalue: string, exdays: number) {
    const date = new Date();
    date.setTime(date.getTime() + exdays * 24 * 60 * 60 * 1000);
    const expires = "expires=" + (date as any).toGMTString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
  }
  
  //获取Cookie
 export function getCookie(cname: string) {
    const name = cname + "=";
    const ca = document.cookie.split(";");
    for (let i = 0; i < ca.length; i++) {
      const c = ca[i].trim();
      if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
      }
    }
    return "";
}

export function removeCookie(cname: string) {
    const name = cname + "=";
    const ca = document.cookie.split(';');
    let cookieStr = "";
    for (let i = 0; i < ca.length; i++) {
      const c = ca[i].trim();
      if (c.indexOf(name) == 0) {
        document.cookie = c + ';expires=' + new Date(0).toUTCString()
      } else {
        cookieStr += c;
        cookieStr += ";";
      }
      document.cookie = cookieStr;
  
    }
  
  }